package com.nice.demo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

import com.nice.demo.test.DrawType;
import com.nice.demo.test.MyHandWritingView;


/**
 * auth: yyj
 * time: 2018/7/5
 */

public class ViewPagerAdapter extends PagerAdapter {
    private Context mContext;

    public ViewPagerAdapter(Context context) {
        mContext = context;
    }

    @Override
    public int getCount() {
        return 6;
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    // PagerAdapter只缓存三张要显示的图片，如果滑动的图片超出了缓存的范围，就会调用这个方法，将图片销毁
    @Override
    public void destroyItem(ViewGroup view, int position, Object object) {
//        view.removeView(images.get(position));
    }

    // 当要显示的图片可以进行缓存的时候，会调用这个方法进行显示图片的初始化，我们将要显示的ImageView加入到ViewGroup中，然后作为返回值返回即可
    @Override
    public Object instantiateItem(ViewGroup view, int position) {
        View childView = View.inflate(mContext, R.layout.lv_item, null);
        view.addView(childView);
        MyHandWritingView handWritingView = (MyHandWritingView) childView.findViewById(R.id.hand_writing_view);
        handWritingView.setDrawType(DrawType.RECTANGLE);
        return childView;
    }
}
